﻿// -----------------------------------------------------------------------
// <copyright file="UpdateLinkTitleCommandHandler.cs">
// Copyright (c) 2013-2014 Andrey Veselov. All rights reserved.
// License:  Microsoft Public License (MS-PL)
// Contacts: http://andrey.moveax.com  andrey@moveax.com
// </copyright>
// -----------------------------------------------------------------------

namespace Moveax.DataAccess.Cqrs.Highway.EF.UnitTests.DataAccess.CommandHandlers.Links
{
	using System.Diagnostics.Contracts;
	using Moveax.DataAccess.Cqrs.Highway.EF.UnitTests.DataAccess.Database.Dto;
	using Moveax.DataAccess.Cqrs.Highway.EF.UnitTests.Model.Commands.Links;

	internal class UpdateLinkTitleCommandHandler : ICommandHandlerSync<UpdateLinkTitleCommand>
	{
		private readonly IRepository _repository;

		public UpdateLinkTitleCommandHandler(IRepository repository)
		{
			Contract.Requires(repository != null);

			this._repository = repository;
		}

		public void Execute(UpdateLinkTitleCommand command)
		{
			var link = new LinkDto() {
				Id = command.Id,
				Title = command.Title,
				Url = "http://somesite.com" // value for EF validation engine, but it should be ignored on update
			};

			this._repository.UpdateExcludeProperties(link,
				l => l.Url,
				l => l.UserProfileId);
		}
	}
}
